package com.dfrz.ch06;

/**
 * 作者：wangmaokang
 * 日期: 2021/4/13 10:43
 * 描述: 二分查找
 */
public class TwoWaySearchTest {
    public static void main(String[] args) {

        System.out.println(search(99));
    }

    public static int search(int i){

        int[] ints={12,34,44,55,56,68,67,99,102,111};

        int low=0;   //最大值
        int high=ints.length-1; //最小值
        while (low<=high){
            int mid=(low+high)/2;//渠道中间的值
            if (ints[mid]==i){
                return mid;
             }else if (ints[mid]>=i){
                high=mid-1;
            }else {
                low=mid+1;
            }
        }

        return -1;//表示没有找到

    }
}
